/**
 * Created by 1 on 2016/12/30.
 */
(function(){
    "use strict";
    function Canvas(canvasId,width,height){
        this.elements=document.getElementById(canvasId);
        this.context=this.elements.getContext("2d");
        this.width=width;
        this.height=height;
        this._init();
    }
    Canvas.prototype={
        constructor:Canvas,
        _init:function(){
            this.elements.width=this.width;
            this.elements.height=this.height;
        },
        //刷新画布
        clear:function(fromX,fromY,cutWidth,cutHeight){
            fromX=fromX || 0;
            fromY=fromY || 0;
            cutWidth=cutWidth || this.width;
            cutHeight=cutHeight || this.height;
            this.context.clearRect(fromX,fromY,cutWidth,cutHeight);
        },
        drawText:function(text){
            this.clear(0,0);
            this.context.font="normal 25px Arial";
            this.context.fillStyle="purple";
            this.context.textAlign="center";
            this.context.fillText(text,this.width/2,45);
        }
    };
    window.Canvas=Canvas;
})();